<?php

class news {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty,$page='',$cat='',$product='') {
		$this->db = $db;
		$this->smarty = $smarty;
		$this->page = $page;
		$this->cat = $cat;
		$this->product = $product;
	}
	
	public function main() {
		$this->ListNews();
		$this->smarty->display("news.tpl");	
	}
	
	public function ListNews() {
		$id = document::GetIdFromLink($this->cat);
		$count = FIN_newsBean::count_news($this->db,$_SESSION['LC_ALL'],'');
		
		$link = FOLDER_HOST.$this->page.'/'.$linkid;
		if($this->cat!=''  ){
				$active = document::GetIdFromLink($this->cat);
				}	
				//echo $this->cat;
		$news['data'] = FIN_newsBean::getAllNewsSharePage($this->db,$_SESSION['LC_ALL'],MAX_DEMO_NEWS,"list",'');
		if($news['data']!=""){
			foreach($news['data'] as $key => $item){
				if($key==0)
					$detailid = $item->news_id;
				if($this->cat!=''){
						if($active == $item->news_id)
							$item->active = '-over';
				}else{
					if($key==0)
						$item->active = '-over';
				}
				
				$item->pro_link=document::RewriteLink($item->news_id,$item->news_title)."/";
				$item->news_short = str_replace('<p>','', $item->news_short);
				$item->news_short = str_replace('</p>','', $item->news_short);
			}
		}
		$result = Paging::do_paging($count,$news, MAX_DEMO_NEWS, $link,"?list",'list');
		
		if($this->cat!=''){
			$detailid = document::GetIdFromLink($this->cat);
		}
		$this->ListNewsDetail($detailid);
		$this->smarty->assign("NEWS", $result);	
		$this->smarty->assign('LINKPRODUCT',$this->page.'/');
	}	
	
	public function ListNewsDetail($id) {
		$news = FIN_newsBean::getNews($this->db,$_SESSION['LC_ALL'], $id);
		$news->news_content=document::ChangePath($news->news_content);
		$news->news_content=document::ChangeLink($news->news_content);
		$strtags=document::ChangeLinkTags($news->tags);
		$arrtags = array();
		for($i=0;$i<count($strtags);$i++){
			$arrtags[$i] = array('name'=>$strtags[$i],"link"=>urlencode($strtags[$i]));	
		}
		
		$news->tags=$arrtags;
		$this->smarty->assign("NEWSDETAILS", $news);
		$this->smarty->assign('PATH',UPLOAD_PRODUCT);	
	}	
	
}
?>
